<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/3/1
 * Time: 15:04
 * Mail:87658989@qq.com
 */

namespace app\api\controller\passenger;
use \think\Db;
use app\api\model;
/**
 * @name【部门接口】
 * @baseurl【passenger】
 * @file【passenger/Agent.php】
 */
class Agent extends Base
{
    protected $beforeActionList = [];
    /**
     * @name【用车公司查询额度】
     * @desc【用车公司查询额度】
     * @uri【getUserQuote】
     * @method【post】
     * @param【
     * ptoken $ string $ abc $token $ 1
     * 】
     * @return【
     * code $ int $ number|1-1 $ 标识1-成功 0-失败#
     * msg $ string $  $ code=0，错误信息#
     * data $ string $ $ 包含字段的数据 ${"quota":"90000.00","unit_quota":"0.00","used_quota":"0"}
     * 】
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getUserQuote(){
        // TODO 财政额度结算周期关联
        $passenger_id = $this->passengerInfo['passenger_id'];
        $field        = 'quota,unit_quota,used_quota';
        $data         = Db::name('passenger')->alias('p')->join('company cu','cu.company_id = p.company_id', 'left')->where('passenger_id',$passenger_id)->field($field)->find();
        $use          = (new model\Company())->getUseMoneyByPassenger($passenger_id);
        $data['used_quota']      = $use['office_money'];
        $data['used_unit_quota'] = $use['company_money'];
        return $this->retSucc(['data'=>$data]);
    }
}